﻿namespace Wicresoft.Busi.BizLogic
{
    using System;
    using System.Web.UI;
    using System.Web.UI.WebControls;

    public class StyleCommon
    {
        public static void SetDropDownListStyle(DropDownList ddl)
        {
            ddl.CssClass = "nmTxt";
        }

        public static void SetStyle(ControlCollection Controls)
        {
            foreach (Control ctl in Controls)
            {
                TextBox txb = ctl as TextBox;
                if (txb != null)
                {
                    SetTextBoxStyle(txb.ReadOnly, txb);
                }
                else
                {
                    DropDownList ddl = ctl as DropDownList;
                    if (ddl != null)
                    {
                        SetDropDownListStyle(ddl);
                    }
                }
            }
        }

        public static void SetStyle(bool isReadOnly, Control Control)
        {
            SetStyle(isReadOnly, Control, true);
        }

        public static void SetStyle(bool isReadOnly, ControlCollection Controls)
        {
            SetStyle(isReadOnly, Controls, true);
        }

        public static void SetStyle(bool isReadOnly, Control Control, bool bSetReadOnly)
        {
            TextBox txb = Control as TextBox;
            if (txb != null)
            {
                SetTextBoxStyle(isReadOnly, txb);
                if (bSetReadOnly)
                {
                    txb.ReadOnly = isReadOnly;
                }
            }
            else if (!isReadOnly)
            {
                DropDownList ddl = Control as DropDownList;
                if (ddl != null)
                {
                    SetDropDownListStyle(ddl);
                }
            }
        }

        public static void SetStyle(bool isReadOnly, ControlCollection Controls, bool bSetReadOnly)
        {
            foreach (Control ctl in Controls)
            {
                SetStyle(isReadOnly, ctl, bSetReadOnly);
            }
        }

        public static void SetTextBoxStyle(bool isReadOnly, TextBox txb)
        {
            string cssClass = txb.CssClass;
            if (((cssClass.CompareTo(string.Empty) == 0) || (cssClass.CompareTo("roTxt") == 0)) || (cssClass.CompareTo("nmTxt") == 0))
            {
                if (isReadOnly)
                {
                    txb.CssClass = "roTxt";
                }
                else
                {
                    txb.CssClass = "nmTxt";
                }
            }
        }
    }
}

